/*
 * Wazuh databaseFeedManager
 * Copyright (C) 2015, Wazuh Inc.
 * September 26, 2023.
 *
 * This program is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General Public
 * License (version 2) as published by the FSF - Free Software
 * Foundation.
 */
#ifndef _TRAMPOLINE_POLICYMANAGER_HPP
#define _TRAMPOLINE_POLICYMANAGER_HPP

#include "MockPolicyManager.hpp"
#include "json.hpp"
#include "observer.hpp"

#include <memory>
#include <string>
#include <unordered_set>

extern std::shared_ptr<MockPolicyManager> spPolicyManagerMock;

/**
 * @brief This class is a wrapper of the trampoline policy manager library.
 */
class TrampolinePolicyManager : public Singleton<TrampolinePolicyManager>
{
public:
    /**
     * @brief Constructor for creating a TrampolinePolicyManager object.
     *
     * The `TrampolinePolicyManager` constructor initializes a new instance of the
     * TrampolinePolicyManager class.
     *
     */
    TrampolinePolicyManager() = default;

    virtual ~TrampolinePolicyManager() = default;

    /**
     * @brief Initializes manager.
     *
     * @param configuration Manager configuration.
     */
    void initialize(const nlohmann::json& configuration)
    {
        spPolicyManagerMock->initialize(configuration);
    }

    /**
     * @brief Loads configuration settings from a JSON object.
     *
     * This function takes a JSON object containing configuration settings and
     * processes them for use by the policy manager's module.
     *
     * @param configuration The JSON object containing configuration settings.
     */
    void loadConfiguration(const nlohmann::json& configuration)
    {
        spPolicyManagerMock->loadConfiguration(configuration);
    }

    /**
     * @brief Validates the configuration settings of the vulnerability-detection's module.
     *
     * This function checks if the configuration settings are valid and conform
     * to the expected format and values. It throw an exception
     * if some value in the configuration is invalid.
     */

    void validateConfiguration()
    {
        spPolicyManagerMock->validateConfiguration();
    }

    /**
     * @brief Validates and configures the vulnerability detection based on the provided JSON object.
     *
     * This function takes a JSON object as input, which is expected to contain configuration
     * information for vulnerability detection. It validates the JSON object to ensure it contains the
     * required fields and has valid values. If the validation passes, no exception is thrown.
     *
     * @param vdObj A constant reference to a JSON object representing the vulnerability detection's configuration.
     *
     * @note This function assumes that the provided JSON object follows a specific format.
     * @note If validation fails, this function throws std::runtime exception.
     */

    void validateAndConfigureVulnerabilityDetection(const nlohmann::json& vdObj)
    {
        spPolicyManagerMock->validateAndConfigureVulnerabilityDetection(vdObj);
    }

    /**
     * @brief Validates and configures the indexer based on the provided JSON object.
     *
     * This function takes a JSON object as input, which is expected to contain configuration
     * information for the indexer. It validates the JSON object to ensure it contains the
     * required fields and has valid values, based on the previous configuration of the vulnerability detection.
     * If the validation passes, no exception is thrown.
     *
     * @param idObj A constant reference to a JSON object representing the indexer's configuration.
     *
     * @note This function assumes that the provided JSON object follows a specific format.
     * @note If validation fails, this function throws std::runtime exception.
     */

    void validateAndConfigureIndexer(const nlohmann::json& idObj)
    {
        spPolicyManagerMock->validateAndConfigureIndexer(idObj);
    }

    /**
     * @brief Adds subscriber.
     *
     * @param subscriber Subscriber to be added.
     */
    void addSubscriber(std::shared_ptr<Observer<nlohmann::json&>> subscriber)
    {
        spPolicyManagerMock->addSubscriber(subscriber);
    }

    /**
     * @brief Removes subscriber.
     *
     * @param observerId Observer ID.
     */
    void removeSubscriber(const std::string& observerId)
    {
        spPolicyManagerMock->removeSubscriber(observerId);
    }

    /**
     * @brief Get updater configuration.
     *
     * @return nlohmann::json Configuration.
     */
    nlohmann::json getUpdaterConfiguration() const
    {
        return spPolicyManagerMock->getUpdaterConfiguration();
    }

    /**
     * @brief Get exclusions.
     *
     * @return nlohmann::json Exclusions configuration.
     */
    nlohmann::json getExclusions() const
    {
        return spPolicyManagerMock->getExclusions();
    }

    /**
     * @brief Get indexer connector configuration.
     *
     * @return nlohmann::json Connector configuration.
     */
    nlohmann::json getIndexerConfiguration() const
    {
        return spPolicyManagerMock->getIndexerConfiguration();
    }

    /**
     * @brief Get vulnerability detection configuration.
     *
     * @return nlohmann::json vulnerability-detection configuration.
     */
    nlohmann::json getVulnerabilityDetection() const
    {
        return spPolicyManagerMock->getVulnerabilityDetection();
    }

    /**
     * @brief Get vulnerability detection status.
     *
     * @return true if enabled or false if not.
     */
    bool isVulnerabilityDetectionEnabled() const
    {
        return spPolicyManagerMock->isVulnerabilityDetectionEnabled();
    }

    /**
     * @brief Get indexer status.
     *
     * @return true if enabled or false if not.
     */
    bool isIndexerEnabled() const
    {
        return spPolicyManagerMock->isIndexerEnabled();
    }

    /**
     * @brief Get feed url.
     *
     * @return std::string feedUrl.
     */
    std::string getFeedUrl() const
    {
        return spPolicyManagerMock->getFeedUrl();
    }

    /**
     * @brief Get feed url.
     *
     * @return std::string feedUrl.
     */
    long getFeedUpdateTime() const
    {
        return spPolicyManagerMock->getFeedUpdateTime();
    }

    /**
     * @brief Get feed url.
     *
     * @return std::string feedUrl.
     */
    std::unordered_set<std::string> getHostList() const
    {
        return spPolicyManagerMock->getHostList();
    }

    /**
     * @brief Get certificate authorities.
     *
     * @return std::unordered_set caList.
     */
    std::unordered_set<std::string> getCAList() const
    {
        return spPolicyManagerMock->getCAList();
    }

    /**
     * @brief Get username.
     *
     * @return std::string username.
     */
    std::string getUsername() const
    {
        return spPolicyManagerMock->getUsername();
    }

    /**
     * @brief Get password.
     *
     * @return std::string password.
     */
    std::string getPassword() const
    {
        return spPolicyManagerMock->getPassword();
    }

    /**
     * @brief Get certificate.
     *
     * @return std::string certificate.
     */
    std::string getCertificate() const
    {
        return spPolicyManagerMock->getCertificate();
    }

    /**
     * @brief Get key.
     *
     * @return std::string key.
     */
    std::string getKey() const
    {
        return spPolicyManagerMock->getKey();
    }

    /**
     * @brief Get CTI url.
     * @return std::string CTI-Server url.
     */
    std::string getCTIUrl() const
    {
        return spPolicyManagerMock->getCTIUrl();
    }

    /**
     * @brief Get translation LRU size.
     *
     * @return uint32_t translation LRU size.
     */
    uint32_t getTranslationLRUSize() const
    {
        return spPolicyManagerMock->getTranslationLRUSize();
    }

    /**
     * @brief Get osdata LRU size.
     *
     * @return uint32_t osdata LRU size.
     */
    uint32_t getOsdataLRUSize() const
    {
        return spPolicyManagerMock->getOsdataLRUSize();
    }

    /**
     * @brief Get remediation LRU size.
     *
     * @return uint32_t remediation LRU size.
     */
    uint32_t getRemediationLRUSize() const
    {
        return spPolicyManagerMock->getRemediationLRUSize();
    }
};

#endif //_TRAMPOLINE_POLICYMANAGER_HPP
